<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/2/16 0016
 * Time: 23:42
 */

namespace app\Lib\Model\User;


use app\Lib\Exception\BlException;
use app\Lib\InterfaceIn\Role\RoleHandle;
use app\Lib\InterfaceIn\User\UserHandle;
use app\Lib\Model\DbModel\UserBase;
use app\Lib\InterfaceIn\User\OperationUserBase as Api;
use app\validate\UserBaseValidate;

class OperationUserBase implements Api
{
    protected $account;
    protected $mobilephone;
    protected $weixin;
    protected $sex;
    protected $regIp;
    protected $birthday;
    protected $nickname;
    protected $qqNumber;
    protected $weixinNumber;
    protected $eMail;
    protected $uid;
    protected $table;
    /** @var UserHandle $opUser */
    protected $opUser;
    protected $prefix = 'anbang';
    /** @var RoleHandle $role */
    protected $role;
    protected $validate;
    protected $accountStatus;
    protected $password;
    protected $auth =[];

    /**
     * @param $account
     * @return $this
     */
    public function setAccount($account)
    {
        $this->account = $account;
        return $this;
    }


    /**
     * @param $mobilephone
     * @return $this
     */
    public function setMobilephone($mobilephone)
    {
        $this->mobilephone = $mobilephone;
        return $this;
    }


    /**
     * @param $weixin
     * @return $this
     */
    public function setWeixin($weixin)
    {
        $this->weixin = $weixin;
        return $this;
    }


    /**
     * @param $sex
     * @return $this
     */
    public function setSex($sex)
    {
        $this->sex = $sex;
        return $this;
    }


    /**
     * @param $regIp
     * @return $this
     */
    public function setRegIp($regIp)
    {
        $this->regIp = $regIp;
        return $this;
    }


    /**
     * @param $birthday
     * @return $this
     */
    public function setBirthday($birthday)
    {
        $this->birthday = $birthday;
        return $this;
    }


    /**
     * @param $nickname
     * @return $this
     */
    public function setNickname($nickname)
    {
        $this->nickname = $nickname;
        return $this;
    }


    /**
     * @param $qqNumber
     * @return $this
     */
    public function setQqNumber($qqNumber)
    {
        $this->qqNumber = $qqNumber;
        return $this;
    }


    /**
     * @param $weixinNumber
     * @return $this
     */
    public function setWeixinNumber($weixinNumber)
    {
        $this->weixinNumber = $weixinNumber;
        return $this;
    }


    /**
     * @param $eMail
     * @return $this
     */
    public function setEMail($eMail)
    {
        $this->eMail = $eMail;
        return $this;
    }

    public function setUid($uid){
        $this->uid = $uid;
        return $this;
    }

    /**
     * @param RoleHandle $role
     * @return OperationUserBase
     */
    public function setRole(RoleHandle $role)
    {
        $this->role = $role;
        return $this;
    }

    /**
     * 账号是否禁用
     * @param $status
     * @return $this
     */
    public function setAccountStatus($status)
    {
        $this->accountStatus = $status;
        return $this;
    }

    public function setPassword($password)
    {
        $this->password = $password;
        return $this;
    }

    /**
     * 设置用户私有权限
     * @param $auth
     * @return mixed
     */
    public function setAuth($auth)
    {
        if(!empty($auth) && !is_array($auth)){
            $auth = json_decode($auth,true);
        }
        $this->auth = $auth;
        return $this;
    }


    /**
     * @param UserHandle $opUser
     * @return OperationUserBase
     */
    public function setOpUser( UserHandle $opUser)
    {
        $this->opUser = $opUser;
        return $this;
    }

    protected function getTable(){
        if(empty($this->table)){
            $this->table = new UserBase();
        }
        return $this->table;
    }

    protected function neatenData(){
        $table = $this->getTable();
        $data = [
            $table->_nickname=>$this->nickname,
            $table->_account=>$this->account,
            $table->_birthday=>$this->birthday,
            $table->_mobilephone=>$this->mobilephone,
            $table->_sex=>$this->sex,
            $table->_weixin=>$this->weixin,
        ];
        return $data;
    }

    protected function getValidate(){
        if(empty($this->validate)){
            $this->validate = new UserBaseValidate();
        }
        return $this->validate;
    }
}